const { querySql, updateSql, insertSql, deleteSql } = require("../db");

function getSemesterList(query) {
  const { semesterName } = query;
  return querySql(
    `select * from semester_list where semesterName like '%${
      semesterName || ""
    }%' ORDER BY startTime DESC`
  );
}

function editSemester(query) {
  return updateSql(query, "semester_list", `where id = ${query.id}`);
}

function createSemester(query, cardId) {
  query.createTime = new Date();
  query.createId = cardId;
  return insertSql(query, "semester_list");
}

function deleteSemester(query) {
  return deleteSql("id", query.id, "semester_list");
}

module.exports = {
  getSemesterList,
  editSemester,
  createSemester,
  deleteSemester,
};
